<template>
    <el-drawer
    :title="this.$t('buttons.newBranch')"
    :visible.sync="drawer"
    :close-on-press-escape="false"
    custom-class="branchBox"
    :wrapperClosable="closable"
    :show-close="showClose"
    :direction="direction"
    @close="closeDrawer">
        <div class="branchCom">
            <div class="flex searchItem">
                <el-input
                :placeholder="this.$t('placeholder.content')"
                v-model="branchName"
                class="searchInput"
                clearable>
                </el-input>
            </div>
            <div class="flex formBtns">
                <el-button type="primary" @click="addBranchBtn">{{ this.$t("buttons.addTrajectory")}}</el-button>
            </div>
        </div>
    </el-drawer>
</template>

<script>
import { showBranch, newBranch } from '../js/branch';
export default {
    name: 'branch',
    components:{
        
    },
    data(){
        return{
            drawer: this.$store.state.showBranch,
            direction: 'btt',
            closable: true,
            showClose: false,
            branchName: ""
        }
    },
    methods:{
        //提交分支
        addBranchBtn: function(){
            let branchStatus = newBranch(this.branchName);
            if(branchStatus){
                showBranch(false);
            }
        },
        //关闭模态框
        closeDrawer: function(){
            showBranch(false);
        }
    },

    //属性监听
    watch:{
       "$store.state.showBranch": function(val){
           this.drawer = val;
        }
    }

}
</script>

<style scoped lang="less">
.branchCom{
    width: 100%;
    padding: 0 15px;
    .formBtns{
        padding: 0 5px;
        margin-top: 25px;
        button{
            width: 100%;
        }
    }
}


</style>